package com.corpgovernment.organization.metric;

import com.ctrip.corp.obt.metric.Metrics;
import com.ctrip.corp.obt.metric.spectator.api.Id;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class MetricService {

    /**
     * 人员信息批量导入
     */
    public static final Id ORGANIZATION_MANAGE_IMPORT_EMPLOYEE = Metrics.REGISTRY.createId("organization.manage.import.employee");
    /**
     * 人员信息批量导出
     */
    public static final Id ORGANIZATION_MANAGE_DOWNLOAD_EMPLOYEE = Metrics.REGISTRY.createId("organization.manage.download.employee");

    /**
     * 组织信息批量导入
     */
    public static final Id ORGANIZATION_MANAGE_IMPORT_ORG = Metrics.REGISTRY.createId("organization.manage.import.org");
    /**
     * 组织信息批量导出
     */
    public static final Id ORGANIZATION_MANAGE_DOWNLOAD_ORG = Metrics.REGISTRY.createId("organization.manage.download.org");

    public static final Id ORGANIZATION_MANAGE_MENU_USE = Metrics.REGISTRY.createId("organization.manage.menu.use");

    public static final Id ORGANIZATION_SUPPLIER_COMPANY_NONE = Metrics.REGISTRY.createId("organization.supplier.company.none");

    public static final String SYNC = "sync";
    public static final String ASYNC = "async";

    public static void metricOrgOrEmployeeCounter(Id id, boolean success, String position) {
        Metrics.REGISTRY.counter(id
                        .withTag("success", success)
                        .withTag("position", position))
                .increment();
    }

    public static void metricMenuCounter(Id id, boolean success) {
        try {
            Metrics.REGISTRY.counter(id
                            .withTag("success", success))
                    .increment();
        }catch (Exception e){
            log.error("record error", e);
        }

    }

    public static void metricSupplierCounter(Id id) {
        try {
            Metrics.REGISTRY.counter(id)
                    .increment();
        }catch (Exception e){
            log.error("record error", e);
        }

    }
}
